<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Gallery/classes/PhpFox_ComponentApprove.class.php, $Author:  $ */



/** Component for approving pictures in gallery
 * @version $Id: PhpFox_ComponentApprove.class.php 389 2008-03-04 13:52:48Z phpfoxsv $
 *
 * @package module.gallery
 */
class PhpFox_Mod_Gallery_ComponentApprove extends BaseComponent
{
    function process()
    {
    	$oSrvAccount = &App::getModuleService('Account', 'Account');

        $oGalleryService = &$this->_oModule->getService('Gallery');
        /* @var $oGalleryService PhpFox_Mod_Gallery_ServiceGallery */
        $oGalleryItem = &$this->_oModule->getItem('Gallery');
        /* @var $oGalleryItem PhpFox_Mod_Gallery_ItemGallery */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        App::loadClass('Pager');
        $oTpl = &$this->_oModule->getTemplate();
        $oUrl = &App::getUrl();
        if (!$oSecurityService->hasStaffPerm('MENU_approve_pics'))
        {
            App::gotoUrl('admin.main');
        }

        if ( $oReq->get('approve') || $oReq->get('delete') )
        {
        	$aPost = $oReq->getArray('val');
        	foreach($aPost as $aItem)
        	{
        		if ( isset($aItem['id']) )
        		{
        			if ( $oReq->get('approve') )
        			{
						$aData['allow'] = '';
            			$aData['feature'] = (isset($aItem['feature']) ? 1 : '');
            			$aData['category'] = $aItem['category'];
            			$aData['who_view'] = $aItem['who_view'];
            			$this->oDatabase->update(App::getT('main'), $aData, "id = '". $aItem['id'] ."'");
        			}
        			elseif ( $oReq->get('delete') )
        			{
        				$oGalleryService->deleteItem($aItem['id']);
        			}
        		}
        	}

            $oUrl->setParam('page', $oReq->get('page', 1));
			App::forward($oUrl->getUrl());
        }

        $iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('admin.pagesize');

        $aCond = array
        (
            1 => 'allow = "1"',
        );

		$sLeftJoin = array();
        $sLeftJoin[] = "". App::getT('user') ." AS u ON(ma.user_id = u.id)";

        list($aItems, $iCnt) = $oGalleryItem->getList($aCond, $iPage, $iPageSize, 'id DESC', '', '', 'ma.id, ma.category, ma.who_view, u.user', $sLeftJoin);

        $oPager = &new Pager($iCnt, $iPage, $iPageSize);
        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);
        $oTpl->assign(array(
            'aItems'     => $aItems,
            'aPaging'    => ($iCnt) ? $oPager->getInfo($oUrl) : '',
            'sImagePath' => App::getParam('gallery.pic.url'),
            'iFrom'      => ($iCnt) ? ($iFrom + 1) : 0,
            'iTo'        => $iTo,
            'iPage'      => $iPage,
            'iCnt'       => $iCnt,
            'aPrivacySettings' => $oSrvAccount->getPrivacySettings(),
            'aCategories'    => App::getOptions('image_cat')
        ));
        $sHtml = $oTpl->fetch('Approve.html');
        return $sHtml;
    }
}
?>